package com.tarena.csmall.seckill.controller;

import cn.tedu.mall.common.restful.JsonResult;
import cn.tedu.mall.pojo.seckill.dto.SeckillOrderAddDTO;
import cn.tedu.mall.pojo.seckill.vo.SeckillCommitVO;
import com.tarena.csmall.seckill.service.SeckillCommitService;
import java.util.UUID;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 只负责接收秒杀下单的请求
 */
@RestController
public class SeckillCommitController {
    @Autowired
    private SeckillCommitService seckillCommitService;
    @PostMapping("/seckill/{randCode}")
    public JsonResult<SeckillCommitVO> commitSeckill(SeckillOrderAddDTO orderAddDTO,
        @PathVariable String randCode){
        //SN没有传递的,自定义生成
        String sn = UUID.randomUUID().toString();
        orderAddDTO.setSn(sn);
        //调用业务层,计算,发送消息
        SeckillCommitVO seckillCommitVO=seckillCommitService.commitSeckill(orderAddDTO,randCode);
        return JsonResult.ok(seckillCommitVO);
    }
}
